//
// Created by root on 19-10-16.
//

#include <gles_utility.h>
#include <android_utility.h>
#include "game.h"
#include "game_step_1.h"
#include "game_step_2.h"
#include "game_step_3.h"
#include "game_step_4.h"
#include "game_step_5.h"
#include "game_step_6.h"
#include "game_step_7.h"

extern "C" JNIEXPORT void JNICALL
Java_com_andova_game_SampleGameRender_onSurfaceCreated(JNIEnv *env, jobject, jobject assetManager,
                                                       jobject bitmap) {
    LOGI("jni onSurfaceCreated");
    device.jniEnv = env;
    device.bitmap = bitmap;
    device.assetManager = assetManager;
    glClearColor(0.0, 0.0, 0.0, 0.0);
    char vBuffer[GLSL_BUFFER_SIZE] = {};
    char fBuffer[GLSL_BUFFER_SIZE] = {};
    glesGetTextForAsset(env, assetManager, GLSL_VERTEX_SHADER_FILE_NAME, vBuffer);
    glesGetTextForAsset(env, assetManager, GLSL_FRAGMENT_SHADER_FILE_NAME, fBuffer);
    GLuint program = glesInitialize(vBuffer, fBuffer);
    device.program = program;
    glUseProgram(program);
    GLES_METHOD_ON_SURFACE_CREATED;
}

extern "C" JNIEXPORT void JNICALL
Java_com_andova_game_SampleGameRender_onSurfaceChanged(JNIEnv *, jobject, jint w, jint h) {
    LOGI("jni onSurfaceChanged, width:%d, height:%d", w, h);
    glViewport(0, 0, w, h); // 设置视口
    device.width = w;
    device.height = h;
    GLES_METHOD_ON_SURFACE_CHANGED;
}

extern "C" JNIEXPORT void JNICALL
Java_com_andova_game_SampleGameRender_onDrawFrame(JNIEnv *, jobject) {
//    glClear(GL_COLOR_BUFFER_BIT);
    GLES_METHOD_ON_DRAW_FRAME;
}